﻿//-------------------------[Popup2]-----------------------------------------------------
/*
    功能：显示一个弹出窗口.
    
    前置支持：Tools.js
*/
function Popup2(panelID, triggerID, styleCss, openCallFunc,closeCallFunc)
{
    var T = this;
    this.MaskAlpha = 30; //屏蔽层透明度1-100
    this.MaskColor = "#99aacc"; //屏蔽层颜色
    this.offsetLeft = 0;//弹出框向左右（左为负，右为正）的偏移量
    this.AddStyle = (styleCss != null && styleCss != "") ? styleCss : "";
	this.Panel 		= document.getElementById(panelID); 	//	面板对象
	this.Trigger 	= document.getElementById(triggerID);	//	触发对象
	this.Mask 		= document.createElement("div");			// 屏蔽层
	this.Mask.style.cssText = "position:absolute;	 left:0px;  top:0px;  filter:alpha(opacity=" + T.MaskAlpha + ");  -moz-opacity: " + (T.MaskAlpha / 100) + ";  opacity: " + (T.MaskAlpha / 100) + ";	background-color:" + T.MaskColor + ";  display:none;";
	this.PanelC 	= document.createElement("div");			// 包含面板对象的容器
	this.PanelC.style.cssText = "position:absolute;border:1px solid #cccccc; padding:2px; display:none;background-color:#FFFFFF;" + T.AddStyle;
	//初始化
	this.Init = function()
	{
	    //T.Trigger.parentNode.appendChild(T.Mask);
	    document.body.appendChild(T.Mask);

	    //T.Trigger.parentNode.appendChild(T.PanelC);
	    document.body.appendChild(T.PanelC);
		var pcc = document.createElement("div");
		pcc.style.cssText=  "border:1px  dashed #EEEEEE; ";
		T.PanelC.appendChild(pcc);
		pcc.appendChild(T.Panel);
		
		addEventHandler(T.Trigger,"click", T.Show.bind(T));
		addEventHandler(T.Mask, "click", T.Hide.bind(T));
		addEventHandler(window, "resize", T.resizeMask.bind(T));
    };
    //遮罩、弹出框的位置、大小处理
    this.SetXYWH = function()
    {
        var sz = GetPageSize();
        T.Mask.style.width = sz.PageW;
        T.Mask.style.height = sz.PageH;

        var wh = getLTWH(T.Trigger);
        T.PanelC.style.left = (wh.left +  this.offsetLeft) + "px";
        T.PanelC.style.top = ((wh.top + wh.height) + 0) + "px";
    }
	// 窗口大小改变事件处理
    this.resizeMask = function()
    {
        if (T.Mask.style.display == "none")
        {
            return;
        }
        T.SetXYWH();
    };
	//显示
	this.Show = function()
	{
	    T.Mask.style.display = "";
	    T.PanelC.style.display = "";
	    
	    T.SetXYWH();
	    
	    T.Trigger.blur();
	    

	    if (openCallFunc)
	    {
	        openCallFunc();
	    }
	};
    //隐藏
	this.Hide = function() {
	    T.Mask.style.display = "none";
	    T.PanelC.style.display = "none";
	    if (closeCallFunc) {
	        closeCallFunc();
	    }
	};

	T.Init();
}

